package com.snatch.deal.shop.store.aop;

import com.snatch.deal.shop.store.annotations.TargetDataSource;
import com.snatch.deal.shop.store.dds.DdsHolder;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect  
@Component  
public class DdsAspect {  
    @Before("@annotation(targetDataSource))")  
    public void switchDataSource(TargetDataSource targetDataSource) {
        DdsHolder.setDS(targetDataSource.value());
    }  
  
    @After("@annotation(targetDataSource))")  
    public void restoreDataSource(TargetDataSource targetDataSource) {  
        DdsHolder.release();
    }  
}  